package kmp;

import java.util.Stack;

public class leetCode1614_maxDepth {
    public int maxDepth(String s) {
        if(s == null || s.length() < 2) return 0;
        Stack<Character> stack = new Stack<>();
        int max = 0;
        for (int i = 0; i < s.length(); i++) {
            if(s.charAt(i) == '('){
                stack.add('(');
            }
            if(s.charAt(i) == ')'){
                if(stack.peek() == '('){
                    max = Math.max(stack.size(),max);
                    stack.pop();
                }
            }
        }
        return max;
    }
}
